﻿@model Marbale.BusinessObject.Product

@{
    ViewBag.Title = "Product";
    Layout = null;
}
<div class="modal-header">
    @if (Model.Id > 0)
    {
        <h4 class="modal-title">Edit Product</h4>
    }
    else
    {
        <h4 class="modal-title">New Product</h4>
    }
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="min-width: 10px !important;">&times;</button>
</div>
<div class="modal-body">

    @using (Ajax.BeginForm("InsertOrUpdate", "Product", FormMethod.Post, new AjaxOptions { OnSuccess = "displayMessage" }))
    {
        <div id="editpopup" style="height: 545px">
            <form>
                <div class="productEdit">
                    <div class="row">
                        <label class="col-md-2">Id:</label>
                        @Html.TextBoxFor(m => m.Id, new { @readonly = "readonly", @class = "col-md-2", id = "productId" })
                        <label class="col-md-1">Name:</label>
                        @Html.TextBoxFor(m => m.Name, new { @class = "col-md-3", placeholder = @Html.DisplayNameFor(n => n.Name) })

                        <label class="col-md-1">Active:</label>
                        @Html.CheckBoxFor(m => m.Active, new { @class = "col-md-1" })

                        <label class="col-md-1">DisplayIn POS:</label>
                        @Html.CheckBoxFor(m => m.DisplayInPOS, new { @class = "col-md-1" })
                    </div>

                    <div class="row">
                        <div class="col-md-5">
                            <div class="col-md-13">
                                <label class="col-md-5">Face Value</label>
                                @Html.TextBoxFor(m => m.FaceValue, new { @class = "col-md-6" })
                            </div>
                            <div class="col-md-13">
                                <label class="col-md-5">Price:</label>
                                @Html.TextBoxFor(m => m.Price, new { @class = "col-md-6" })
                            </div>
                            <div class="col-md-13">
                                <label class="col-md-5">TaxInclusive:</label>
                                @Html.CheckBoxFor(m => m.TaxInclusive, new { @class = "col-md-6", @onchange = "TaxDetails('', this.value)", @style = "position:absolute;width:20px;" })

                            </div>
                            <div class="col-md-13">
                                <label class="col-md-5">Tax:</label>
                                @Html.DropDownListFor(m => m.TaxId, new SelectList((List<Marbale.BusinessObject.Tax.TaxSet>)Session["TaxList"], "Id", "Value", selectedValue: string.IsNullOrEmpty(Model.TaxName) ? "SELECT" : Model.TaxName), new { @class = "col-md-6", @style = "height: 35px;font-size: 14px", @onchange = "TaxDetails(this.value)" })
                            </div>
                            <div class="col-md-13">
                                <label class="col-md-5">Tax %:</label>
                                @Html.TextBoxFor(m => m.Taxpercent, new { @class = "col-md-6" })
                            </div>

                            <div class="col-md-13">
                                <label class="col-md-5">Effective Price:</label>
                                @Html.TextBoxFor(m => m.EffectivePrice, new { @class = "col-md-6" })
                            </div>
                            <div class="col-md-13">
                                <label class="col-md-5">Final Price:</label>
                                @Html.TextBoxFor(m => m.FinalPrice, new { @class = "col-md-6" })
                            </div>
                            <div class="col-md-13">
                                <label class="col-md-5">Credits:</label>
                                @Html.TextBoxFor(m => m.Credits, new { @class = "col-md-6" })

                            </div>
                            <div class="col-md-13">
                                <label class="col-md-5">Courtesy:</label>
                                @Html.TextBoxFor(m => m.Courtesy, new { @class = "col-md-6" })
                            </div>
                            <div class="col-md-13">
                                <label class="col-md-5">Bonus:</label>
                                @Html.TextBoxFor(m => m.Bonus, new { @class = "col-md-6" })
                            </div>
                            <div class="col-md-13">
                                <label class="col-md-5">Tickets:</label>
                                @Html.TextBoxFor(m => m.Tickets, new { @class = "col-md-6" })
                            </div>
                            <div class="col-md-13">
                                <label class="col-md-5">Time:</label>
                                @Html.TextBoxFor(m => m.Time, "{0:HH:mm:ss}", new { type = "Time", @class = "col-md-6", @style = "padding-right: 0px;padding-left: 0px;" })
                            </div>
                            <div class="col-md-13">
                                <label class="col-md-5">Category:</label>
                                @Html.DropDownListFor(m => m.Category, new SelectList((List<Marbale.BusinessObject.IdValue>)Session["CategoryList"], "Id", "Value", selectedValue: string.IsNullOrEmpty(Model.Category) ? "SELECT" : Model.Category), new { @class = "col-md-6", @style = "font-size: 14px" })
                            </div>
                            <div class="col-md-13">
                                <label class="col-md-5">Product Type:</label>
                                @Html.DropDownListFor(m => m.Type, new SelectList((List<Marbale.BusinessObject.IdValue>)Session["TypeList"], "Id", "Value", selectedValue: string.IsNullOrEmpty(Model.Type) ? "SELECT" : Model.Type), new { @class = "col-md-6", @style = "font-size: 14px" })
                            </div>
                        </div>
                        <div class="col-md-7">
                            <div class="row">
                                <div class="col-md-5">
                                    <div class="col-md-13">
                                        <label class="col-md-11">Ticket Allowed:</label>
                                        @Html.CheckBoxFor(m => m.TicketAllowed, new { @class = "col-md-4", @style = "position:absolute;width:20px;" })
                                    </div>

                                    <div class="col-md-13">
                                        <label class="col-md-11">OnlyVIP:</label>
                                        @Html.CheckBoxFor(m => m.OnlyVIP, new { @class = "col-md-4", @style = "position:absolute;width:20px;" })
                                    </div>

                                    <div class="col-md-13">
                                        <label class="col-md-11">Quantity Prompt</label>
                                        @Html.CheckBoxFor(m => m.QuantityPrompt, new { @class = "col-md-4", @style = "position:absolute;width:20px;" })
                                    </div>

                                    <div class="col-md-13">
                                        <label class="col-md-11">Allow Price Override</label>
                                        @Html.CheckBoxFor(m => m.AllowPriceOverride, new { @class = "col-md-4", @style = "position:absolute;width:20px;" })
                                    </div>
                                </div>
                                <div class="col-md-7">
                                    <div class="col-md-13">
                                        <label class="col-md-6">POS Counter:</label>
                                        @Html.TextBoxFor(m => m.POSCounter, new { @class = "col-md-5" })
                                    </div>
                                    <div class="col-md-13">
                                        <label class="col-md-6">DisplayGroup:</label>
                                        @Html.DropDownListFor(m => m.DisplayGroupId, new SelectList((List<Marbale.BusinessObject.IdValue>)Session["DisplayGroupList"], "Id", "Value", selectedValue: string.IsNullOrEmpty(Model.DisplayGroup) ? "SELECT" : Model.DisplayGroup), new { @class = "col-md-5" })
                                    </div>
                                    <div class="col-md-13">
                                        <label class="col-md-6">CardValidFor:</label>
                                        @Html.TextBoxFor(m => m.CardValidFor, new { @class = "col-md-5" })
                                    </div>
                                    <div class="col-md-13">
                                        <label class="col-md-8">Minimum quantity:</label>
                                        @Html.TextBoxFor(m => m.MinimumQuantity, new { @class = "col-md-3" })
                                    </div>
                                </div>
                                <div class="col-md-12">
                                    <label class="col-md-8">Auto Generate Card Number:</label>
                                    @Html.CheckBoxFor(m => m.AutoGenerateCardNumber, new { @class = "col-md-4", @style = "position:absolute;width:20px;" })
                                </div>
                                <div class="col-md-12">
                                    <label class="col-md-8">Manager Approval Required</label>
                                    @Html.CheckBoxFor(m => m.ManagerApprovalRequired, new { @class = "col-md-4", @style = "position:absolute;width:20px;" })
                                </div>
                                <div class="col-md-12">
                                    <label class="col-md-8">Transaction Header Remarks Mandatory</label>
                                    @Html.CheckBoxFor(m => m.TrxHeaderRemarksMandatory, new { @class = "col-md-4", @style = "position:absolute;width:20px;" })
                                </div>
                                <br />
                                <br />
                                <br />

                                <div class="col-md-12">
                                    <label class="col-md-6">StartDate:</label>
                                    @Html.TextBoxFor(m => m.StartDate, "{0:yyyy-MM-ddTHH:mm:ss}", new { type = "datetime-local", @class = "col-md-5", @readonly = "readonly", @style = "padding-right: 0px;padding-left: 0px;" })
                                </div>
                                <div class="col-md-12">
                                    <label class="col-md-6">ExpiryDate:</label>
                                    @Html.TextBoxFor(m => m.ExpiryDate, "{0:yyyy-MM-ddTHH:mm:ss}", new { type = "datetime-local", @class = "col-md-5", @style = "padding-right: 0px;padding-left: 0px;" })
                                </div>
                                <div class="col-md-12">
                                    <label class="col-md-6">Last Updated User:</label>
                                    @Html.TextBoxFor(m => m.LastUpdatedBy, new { @class = "col-md-5", @readonly = "readonly" })
                                </div>
                                <div class="col-md-12">
                                    <label class="col-md-6">LastUpdatedDate:</label>
                                    @Html.TextBoxFor(m => m.LastUpdatedDate, new { @class = "col-md-5", @readonly = "readonly" })
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
            </form>
            <div style="float: right; padding-right: 50px">
                <input type="submit" name="submit" value="Save" onclick="duplicateClick(false)" class="btn btn-primary btn-md" />
                @if (Model.Id > 0)
                {
                    <button class="btn btn-primary btn-md" onclick="duplicateClick(true)">Duplicate</button>
                }
               <button class="btn btn-primary btn-md" role="button" data-dismiss="modal" aria-hidden="true">Close</button>
            </div>
        </div>
  
    }
</div>

<script type="text/javascript">
    var duplicateClicked = false;
    function duplicateClick(value) {
        if (value == true) {
            $('#productId').val(0);
        }
        duplicateClicked = value;
    }
    function displayMessage(response) {
        if (duplicateClicked == false) {
            if (response == '') {
                location.reload();
            } else {
                alert(response);
            }
        }
    }

    function TaxDetails(TaxId1, taxinclusive) {
        var TaxId = $('#TaxId option:selected').val();
        var Price = $('#Price').val();
        if (Price == "") {
            Price = null;
        }
        var FaceValue = Number($('#FaceValue').val());
        taxinclusive = $('#TaxInclusive').is(":checked");
        var model = {
            Id: TaxId,
            Price: Price,
            FaceValue: FaceValue,
            TaxInclusive: taxinclusive
        };
        if (TaxId == "") {
            $('#EffectivePrice').val(Price);
            $('#FinalPrice').val(Price);
        }
            //JSON.stringify({ TaxId: TaxId, Price: Price, TaxInclusive: taxinclusive, FaceValue: FaceValue }),
        else {

            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: '@Url.Action("TaxDetails", "Product")',
                data: JSON.stringify({ model: model }),
                dataType: "json",
                success: function (data) {
                    $('#EffectivePrice').val(data.EffectivePrice);
                    $('#Taxpercent').val(data.Taxpercent);
                    $('#FinalPrice').val(data.FinalPrice);
                },
                error: function (e) {
                    alert(e);
                }
            });
        }
    }
</script>
<style>
    .modal-body {
        padding: 5px;
    }
</style>
